namespace wmedu {
    export class OralAddSub2 extends BaseOral implements IOralCreater {

        create(opt: IOralOpt) {
            let paramArea = opt.paramArea;
            let op: Enum_OralOp;
            // 先得到结果值
            let value = MathUtil.randomInt(paramArea[1], paramArea[0]);
            // 再通过随机等号左边第一位数字，大于结果，减，小于结果，只能加
            let p1 = MathUtil.randomInt(paramArea[1], paramArea[0]);
            let p2 = 0;
            if (p1 > value) {
                p2 = p1 - value;
                op = Enum_OralOp.Sub;
            } else if (p1 < value) {
                p2 = value - p1;
                op = Enum_OralOp.Add;
            } else {
                p1 = MathUtil.randomInt(value, 1);
                p2 = value - p1;
                op = Enum_OralOp.Add;
            }
            let idx = MathUtil.randomFloor(2);
            let str = ''
            if (opt.blankSide == 0) {
                if (idx == 0) {
                    str = `${opt.blankStr}${this.mGetOpStr(op)}${p2}=${value}`
                } else {
                    str = `${p1}${this.mGetOpStr(op)}${opt.blankStr}=${value}`
                }
            } else if (opt.blankSide == 1) {
                str = `${p1}${this.mGetOpStr(op)}${p2}=${opt.blankStr}`
            }

            str = BuildUtil.getOralStr(opt.blankSide,opt.blankStr,[p1,p2],[op],value);
            let res: IOralSide = { nums: [p1, p2], ops: [op], value: value, str }
            return res;
        }
    }
}